/*
 * Created by JFormDesigner on Wed Dec 15 12:00:36 CST 2021
 */

package com.cn.项目.飞机预约管理系统.UserFrame;

import com.cn.项目.utils.JdbcUtils;
import com.cn.项目.飞机预约管理系统.Maininterface.Fail;
import com.cn.项目.飞机预约管理系统.Maininterface.Success;

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;


public class CancellationOrder extends JFrame {
    public CancellationOrder() {
        initComponents();
    }

    //确认取消
    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs  = null;
        String name  = textField1.getText();
        String bname  = textField2.getText();
        String state = textField3.getText();
        try {
            conn = JdbcUtils.getConnection();
            String sql="update booktickets set state=? where `name`=? and bname=? ;";
            st = conn.prepareStatement(sql);
            st.setString(1,state);
            st.setString(2,name );
            st.setString(3,bname);
            int i = st.executeUpdate();

            if (i>0){
                new Success();
            }else {
                new Fail();
            }

        } catch (SQLException e1) {
            e1.printStackTrace();
        }finally {

        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        textField1 = new JTextField();
        textField2 = new JTextField();
        button1 = new JButton();
        label4 = new JLabel();
        textField3 = new JTextField();

        //======== this ========
        setVisible(true);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("取消订单");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 15f));
        label1.setForeground(new Color(255, 51, 0));
        contentPane.add(label1);
        label1.setBounds(125, 10, 165, 40);

        //---- label2 ----
        label2.setText("乘客姓名");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 8f));
        contentPane.add(label2);
        label2.setBounds(25, 65, 115, 37);

        //---- label3 ----
        label3.setText("代买姓名");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 6f));
        contentPane.add(label3);
        label3.setBounds(25, 130, 120, 30);
        contentPane.add(textField1);
        textField1.setBounds(185, 65, 165, 40);
        contentPane.add(textField2);
        textField2.setBounds(185, 125, 170, 40);

        //---- button1 ----
        button1.setText("确认取消");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 6f));
        button1.setForeground(new Color(0, 204, 51));
        button1.addActionListener(e -> button1ActionPerformed(e));
        contentPane.add(button1);
        button1.setBounds(120, 250, 140, 45);

        //---- label4 ----
        label4.setText("状态：");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 6f));
        contentPane.add(label4);
        label4.setBounds(30, 185, 75, 35);

        //---- textField3 ----
        textField3.setText("取消");
        contentPane.add(textField3);
        textField3.setBounds(185, 185, 165, 45);

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        textField3.setEditable(false);
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JTextField textField1;
    private JTextField textField2;
    private JButton button1;
    private JLabel label4;
    private JTextField textField3;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
